<template>
  <div class="loginEntry">
    <div class="loginBox">
      <div class="left">
        <div class="logoBox">
          <img src="../../static/newimg/title.png" alt="" />
        </div>
        <div class="login">
          <span>Login User</span>
          <div class="title">用户登录</div>
          <div class="form">
            <el-form
              label-position="top"
              label-width=".8rem"
              :model="ruleForm"
              :rules="rules"
              ref="ruleForm"
              :hide-required-asterisk="true"
            >
              <div class="formBox">
                <div class="formLeft">
                  <el-form-item label="用户名" prop="username">
                    <el-input
                      style="width: 2.54rem;"
                      v-model="ruleForm.username"
                      placeholder="请输入用户名"
                      color="#fff"
                    ></el-input>
                  </el-form-item>
                </div>
                <div class="formRight">
                  <img src="../../static/newimg/user.png" alt="" />
                </div>
              </div>

              <div class="formBox" style="margin-top: .24rem;">
                <div class="formLeft">
                  <el-form-item label="密码" prop="password">
                    <el-input
                      v-model="ruleForm.password"
                      show-password
                      placeholder="请输入密码"
                      color="#fff"
                    ></el-input>
                  </el-form-item>
                </div>
                <div class="formRight">
                  <img src="../../static/newimg/pwd.png" alt="" />
                </div>
              </div>
              <el-form-item label="">
                <el-checkbox
                  style="color: #8D9AAF;"
                  @change="rmbu"
                  v-model="checked"
                  >记住账号</el-checkbox
                >
              </el-form-item>
              <el-form-item style="margin-top: .43rem;">
                <el-button
                  type="primary"
                  style="width: 100%;height: .74rem;border-radius:.37rem;"
                  @click="submitForm('ruleForm')"
                  >登录</el-button
                >
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
      <div class="right">
        <img src="../../static/newimg/backdrop.png" alt="" />
      </div>
    </div>
  </div>
</template>
<script>
import http from "../utils/http";
import api from "../utils/api";
export default {
  data() {
    return {
      ruleForm: {
        username: "",
        password: ""
      },
      checked: false,
      rules: {
        username: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  created() {
    if (window.localStorage.getItem("user") != undefined) {
      this.ruleForm.username = window.localStorage.getItem("user");
    }
  },
  mounted() {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          http.post(api.login, {
              username: this.ruleForm.username,
              password: this.ruleForm.password,
              captcha: ""
            })
            .then(res => {
              if (res.data.code == "200") {
                this.$router.push("/newBlock");
                window.sessionStorage.setItem("token", res.data.data.token);
                window.sessionStorage.setItem("authority", JSON.stringify(res.data.data.userInfo.authorities));
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    rmbu() {
      if (this.checked && this.ruleForm.username != "") {
        window.localStorage.setItem("user", this.ruleForm.username);
      } else {
        window.localStorage.removeItem("user");
      }
    }
  }
};
</script>

<style>
.loginEntry {
  width: 100%;
  height: 100%;
  background-color: #eaeef2;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}
.loginBox {
  display: flex;
  width: 17rem;
  height: 8.5rem;
  border-radius: .4rem;
}
.left {
  position: relative;
  width: 6.03rem;
  height: 100%;
  border-radius: .4rem 0 0 .4rem;
  background-color: #fff;
}
.logoBox {
  position: absolute;
  margin: .4rem 0 0 1rem;
}
.logoBox>img{
  width: 100%;
  height: 100%;
}
.login {
  position: absolute;
  top: 2rem;
  left: 1rem;
  width: 4.4rem;
  height: 5.3rem;
}
.login > span {
  color: var(--606266, #606266);
  font-size: .18rem;
}
.title {
  width: 1.44rem;
  height: .48rem;
  line-height: .48rem;
  color: #333;
  font-size: .36rem;
  font-weight: 700;
}
.form {
  margin-top: .4rem;
  width: 100%;
  height: 2.96rem;
}
.formBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 1.16rem;
  border-radius: .32rem;
  background-color: #f3f6fb;
}
.formLeft {
  margin-left: .4rem;
}
.formRight {
  margin-right: .4rem;
}
.el-form--label-top .el-form-item__label {
  padding: 0 !important;
}
.el-form-item__label {
  line-height: .3rem !important;
  margin-left: .04rem !important;
  font-size: .16rem !important;
  color: #8d9aaf !important;
}
.el-input__inner {
  border: .01rem solid #f3f6fb;
  color: #000 !important;
  font-size: .2rem !important;
  padding: 0 !important;
}
.el-form-item {
  margin-bottom: 0 !important;
}
.right {
  width: 10.97rem;
  height: 100%;
  border-radius: 0 .4rem .4rem 0;
  background-color: #fff;
}
.right>img{
  width: 100%;
  height: 100%;
}
.el-input__inner::-webkit-input-placeholder {
  /* placeholder颜色 */
  color: #aab2bd !important;
}
.el-input--suffix .el-input__inner{
  padding-right: .3rem !important;
}
</style>
